package com.zjb.demo.system.service;

import com.zjb.demo.common.domain.LoginUser;
import com.zjb.demo.system.domain.SysUserOnline;
import org.noear.solon.annotation.Component;

import java.util.Objects;

/**
 * 在线用户 服务层处理
 *
 * @author 庄佳彬
 * @since 2023/12/26 21:59
 */
@Component
public class SysUserOnlineService {

    public SysUserOnline loginUserToUserOnline(LoginUser user) {
        if (Objects.isNull(user) || Objects.isNull(user.getUser())) {
            return null;
        }
        SysUserOnline sysUserOnline = new SysUserOnline();
        sysUserOnline.setTokenId(user.getToken());
        sysUserOnline.setUserName(user.getUsername());
        sysUserOnline.setIpaddr(user.getIpaddr());
        sysUserOnline.setLoginLocation(user.getLoginLocation());
        sysUserOnline.setBrowser(user.getBrowser());
        sysUserOnline.setOs(user.getOs());
        sysUserOnline.setLoginTime(user.getLoginTime());
//        if (!Objects.isNull(user.getUser().getDept())) {
//            sysUserOnline.setDeptName(user.getUser().getDept().getDeptName());
//        }
        return sysUserOnline;
    }

}
